package com.kjc.demo.basic.test;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class WxDirectRequestDTO implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -6574472924481405850L;
	
	public static void main(String[] args) throws JsonProcessingException {
		WxDirectRequestDTO wxDirectRequestDTO = new WxDirectRequestDTO();
		wxDirectRequestDTO.setAppid("123456789");
		wxDirectRequestDTO.setBody("Test");
		Map<String,Object> map = wxDirectRequestDTO.toMap();
		ObjectMapper mapper = new ObjectMapper();
		String jsonStr = mapper.writeValueAsString(map);
		System.out.println(jsonStr);
	}
	
	public Map<String, Object> toMap() {
		Map<String, Object> map = new HashMap<String, Object>();
		Field[] fields = getClass().getDeclaredFields();
		byte b;
		int i;
		Field[] arrayOfField1;
		for (i = (arrayOfField1 = fields).length, b = 0; b < i;) {
			Field field = arrayOfField1[b];

			try {
				Object obj = field.get(this);
				if (obj != null) {
					map.put(field.getName(), obj);
				}
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
			b++;
		}

		return map;
	}
	
	@XmlElement(name = "appid")
	private String appid; //appid是商户在微信申请公众号或移动应用成功后分配的帐号ID
	
	@XmlElement(name = "mch_id")
	private String mch_id; //商户号
	
	@XmlElement(name = "nonce_str")
	private String nonce_str; //随机字符串
	
	@XmlElement(name = "sign")
	private String sign;//签名
	
	@XmlElement(name = "body")
	private String body;//商品描述
	
	@XmlElement(name = "detail")
	private String detail;//商品详情
	
	@XmlElement(name = "attach")
	private String attach;//附加数据 可选
	
	@XmlElement(name = "out_trade_no")
	private String out_trade_no;//商户订单号
	
	@XmlElement(name = "total_fee")
	private String total_fee;//总金额
	
	@XmlElement(name = "fee_type")
	private String fee_type;//货币类型  否 CNY
	
	@XmlElement(name = "spbill_create_ip")
	private String spbill_create_ip;//终端IP
	
	@XmlElement(name = "goods_tag")
	private String goods_tag;//商品标记 可选
	
	@XmlElement(name = "notify_url")
	private String notify_url;//通知URL
	
	@XmlElement(name = "trade_type")
	private String trade_type;//交易类型
	
	@XmlElement(name = "contract_id")
	private String contract_id;//协议号

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public String getMch_id() {
		return mch_id;
	}

	public void setMch_id(String mch_id) {
		this.mch_id = mch_id;
	}

	public String getNonce_str() {
		return nonce_str;
	}

	public void setNonce_str(String nonce_str) {
		this.nonce_str = nonce_str;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public String getAttach() {
		return attach;
	}

	public void setAttach(String attach) {
		this.attach = attach;
	}

	public String getOut_trade_no() {
		return out_trade_no;
	}

	public void setOut_trade_no(String out_trade_no) {
		this.out_trade_no = out_trade_no;
	}

	public String getTotal_fee() {
		return total_fee;
	}

	public void setTotal_fee(String total_fee) {
		this.total_fee = total_fee;
	}

	public String getFee_type() {
		return fee_type;
	}

	public void setFee_type(String fee_type) {
		this.fee_type = fee_type;
	}

	public String getSpbill_create_ip() {
		return spbill_create_ip;
	}

	public void setSpbill_create_ip(String spbill_create_ip) {
		this.spbill_create_ip = spbill_create_ip;
	}

	public String getGoods_tag() {
		return goods_tag;
	}

	public void setGoods_tag(String goods_tag) {
		this.goods_tag = goods_tag;
	}

	public String getNotify_url() {
		return notify_url;
	}

	public void setNotify_url(String notify_url) {
		this.notify_url = notify_url;
	}

	public String getTrade_type() {
		return trade_type;
	}

	public void setTrade_type(String trade_type) {
		this.trade_type = trade_type;
	}

	public String getContract_id() {
		return contract_id;
	}

	public void setContract_id(String contract_id) {
		this.contract_id = contract_id;
	}

	@Override
	public String toString() {
		return "WxDirectRequestDTO [appid=" + appid + ", mch_id=" + mch_id + ", nonce_str=" + nonce_str + ", sign="
				+ sign + ", body=" + body + ", detail=" + detail + ", attach=" + attach + ", out_trade_no="
				+ out_trade_no + ", total_fee=" + total_fee + ", fee_type=" + fee_type + ", spbill_create_ip="
				+ spbill_create_ip + ", goods_tag=" + goods_tag + ", notify_url=" + notify_url + ", trade_type="
				+ trade_type + ", contract_id=" + contract_id + "]";
	}
	
	
	
}
